import { createSlice } from "@reduxjs/toolkit";

const appSlice = createSlice({
  name: "app", // 当前模块名称
  // 当前模块管理数据的初始值
  initialState: {
    count: 0,
  },
  reducers: {
    increment(prevState, action) {
      // prevState --> 之前的状态数据
      // action --> action 对象 { type: xxx, payload: xxx }
      // 允许直接修改状态数据
      prevState.count += action.payload;
    },
    decrement(prevState, action) {
      prevState.count -= action.payload;
    },
  },
});

// 导出 action
export const { increment, decrement } = appSlice.actions;

// 导出 reducer
export default appSlice.reducer;
